package com.ssm.springboot.ExceptionHander;

import com.ssm.springboot.pojo.ErrorInfo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author
 * @create 2018-07-10 15:32
 **/
@ControllerAdvice
public class GloadExceptionHandler {

    @ExceptionHandler(value = MyException.class)
    @ResponseBody
    public ErrorInfo<String> defaultErrorJson(HttpServletRequest request , Exception e){
        ErrorInfo<String> info = new ErrorInfo<>();
        info.setMsg(e.getMessage());
        info.setCode(ErrorInfo.error);
        info.setData("");
        info.setUrl(request.getRequestURI());
        return  info;
    }
}
